#include <hashCommandActuator.h>

int hashCommandActuatorInit(struct hashCommandActuatorManage *atcMng, struct hashCommandActuatorInform *atcBufferSet, uint32_t atcSizeSet)
{
    if (!atcMng)
    {
        logerror("");
        return -1;
    }
    if (!(atcBufferSet && atcSizeSet > 0))
    {
        logerror("");
        return -1;
    }
    atcMng->commandHash = atcBufferSet;
    atcMng->hashSize = atcSizeSet;
    return 0;
}

int hashCommandActuatorRun(struct hashCommandActuatorManage *atcMng, uint32_t commandId, void *inputstring, uint32_t *inputsize)
{
    if (!atcMng)
    {
        logerror("");
        return -1;
    }
    if (!(atcMng->commandHash && atcMng->hashSize > 0))
    {
        logerror("");
        return -1;
    }
    if (commandId >= atcMng->hashSize)
    {
        logerror("%d, %d", commandId, atcMng->hashSize);
        return -1;
    }
    if (!atcMng->commandHash[commandId].callbackFunction)
    {
        logerror("");
        return -1;
    }
    // logdebug("%u", commandId);
    return atcMng->commandHash[commandId].callbackFunction(inputstring, inputsize, atcMng->commandHash[commandId].userdata);
}

// int hashCommandActuatorDirect(hashCommandCallback *commandlist, uint32_t commandsize, uint32_t commandId,
//                                void *inputstring, uint32_t inputsize, void *userdata)
// {
//     if(!commandlist)
//     {
//         logerror("");
//         return -1;
//     }
//     if(!(commandId < commandsize))
//     {
//         logerror("");
//         return -1;
//     }
//     return commandlist[commandId](inputstring, inputsize, userdata);
// }
